<?php
namespace Common\Model;
use Common\Model\ScModel;

class SaleCarsModel extends ScModel
{

	protected $_validate = array(
		//array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
		/*array('brand_id', 'number', '请选择品牌！', self::MUST_VALIDATE, 'regex', CommonModel::MODEL_UPDATE  ),
		array('model_id', 'number', '请选择型号！', self::MUST_VALIDATE, 'regex', CommonModel:: MODEL_UPDATE  ),
		array('year_id', 'number', '请选择年款！', self::MUST_VALIDATE, 'regex', CommonModel:: MODEL_UPDATE  ),
		array('location', 'require', '请填写所在地！',  self::MUST_VALIDATE,  'regex', CommonModel:: MODEL_UPDATE  ),
		array('registration_date_year', array(1972, 2099), '请输入正确的上牌年份(数字年份)！', self::VALUE_VALIDATE, 'between', CommonModel:: MODEL_UPDATE  ),
		array('registration_date_month', array(1, 12), '请选择上牌月份！', self::VALUE_VALIDATE, 'between', CommonModel:: MODEL_UPDATE  ),

		array('mileage', 'require', '请填写行驶里程(数字)！', self::MUST_VALIDATE, 'regex', CommonModel:: MODEL_UPDATE  ),
		array('colour', 'require', '请填写内外颜色！', self::MUST_VALIDATE, 'regex', CommonModel:: MODEL_UPDATE  ),

		array('sale_price', 'require', '请填写预售价格！', self::MUST_VALIDATE, 'regex', CommonModel:: MODEL_UPDATE  ),
		array('transfer_fee', array(0, 1), '请选择是否需要过户费！', self::MUST_VALIDATE, 'between', CommonModel:: MODEL_UPDATE  ),
		array('transfer_times', 'number', '请填写过户次数！', self::MUST_VALIDATE, 'regex', CommonModel:: MODEL_UPDATE  ),

		array('insurance_expired_date_year', array(1972, 2099), '请输入正确的保险到期年份(数字年份)！', self::VALUE_VALIDATE, 'between', CommonModel:: MODEL_UPDATE  ),
		array('insurance_expired_date_month', array(1, 12), '请选择保险到期月份！', self::VALUE_VALIDATE, 'between', CommonModel:: MODEL_UPDATE  ),
		array('annual_inspection_date_year', array(1972, 2099), '请输入正确的年检到期年份(数字年份)！', self::VALUE_VALIDATE, 'between', CommonModel:: MODEL_UPDATE  ),
		array('annual_inspection_date_month', array(1, 12), '请选择年检到期月份！', self::VALUE_VALIDATE, 'between', CommonModel:: MODEL_UPDATE  ),
		array('commercial_insurance_year', array(1972, 2099), '请输入正确的商险到期年份(数字年份)！', self::VALUE_VALIDATE, 'between', CommonModel:: MODEL_UPDATE  ),
		array('commercial_insurance_month', array(1, 12), '请选择商险到期月份！', self::VALUE_VALIDATE, 'between', CommonModel:: MODEL_UPDATE  ),


		array('realname', 'require', '请填写姓名！', self::MUST_VALIDATE, 'regex', CommonModel:: MODEL_UPDATE  ),
		array('mobile', 'require', '请填写电话！', self::MUST_VALIDATE, 'regex', CommonModel:: MODEL_UPDATE  ),
		array('margin_tariff', 'require', '请填写优惠幅度！', self::MUST_VALIDATE, 'regex', CommonModel:: MODEL_UPDATE  ),
		array('owner_words', 'require', '请填写车主自述！', self::MUST_VALIDATE, 'regex', CommonModel:: MODEL_UPDATE  ),*/
	);

	protected $_auto = array(
		//array('create_time','mGetDate',CommonModel:: MODEL_INSERT,'callback'),
	);
	
	//用于获取时间，格式为2012-02-03 12:12:12,注意,方法不能为private
	function mGetDate() {
		return date('Y-m-d H:i:s');
	}

	function checkSale($uid)
	{
		$arr = $this->where("user_id={$uid} and  status=0 ")->find();
		if (is_array($arr)) {
			return $arr;
		} else {
			return false;
		}
	}
}

